// 目录生成工具函数
export function generateTOC(headers) {
  if (!headers) return
  const tocItems = []
  let currentH2 = null

  headers.forEach((header, index) => {
    const id = `heading-${index}`
    // header.id = id

    const tocItem = {
      id,
      text: header.text,
      level: header.level,
      children: [],
    }

    if (tocItem.level === 2) {
      tocItems.push(tocItem)
      currentH2 = tocItem
    } else if (tocItem.level === 3 && currentH2) {
      currentH2.children.push(tocItem)
    }
  })

  return tocItems
}
